**  -------------------------------------------------------------------------
**  PROCEDURE USED TO RETRIEVE THE PATIENT CODE FROM THE MAGNETIC STRIPE CARD
**  CALLED BY : PATR2.PRG
**  DATE: 16-JUNE-2002
**  -------------------------------------------------------------------------

STORE 0 TO WHICH_CTR, DATALEN, CARDHOLDER
** chg req#1
STORE space (60) to CARD_Data
STORE SPACE(5) TO FIELD_SEQNO
STORE SPACE(40) TO FIELD_PNAME
**


DO WHILE WHICH_CTR = 0

** Prompt to ask patient currently in which clinic
   DO BOX3 WITH 10,3,"PATIENT IS NOW IN CLINIC LOCATIONS :","HCMC","HANOI","VUNG TAU",'GR+','RB','GR+','R',WHICH_CTR,.F.,.T.
   IF LASTKEY() = 27
     RETURN
   ENDIF

   @ 8,3 SAY "PLEASE SWIPE CARD THROUGH :"
   DO BOXE WITH 10,3,'CARD DATA:','CARD_DATA','GR+','R','N','W+',60,.F.,.T.

** SEPARATE THE FIELDS DATA
   ** FIELD#1: CARD SEQNO          X(5)
   ** FIELD#2: CARD HOLDER NAME    X(40)
   **
   CARD_DATA = ALLTRIM(CARD_DATA)

   DATALEN = LEN(CARD_DATA)
   FIELD_SEQNO = SUBSTR(CARD_DATA,1,5)
   FIELD_PNAME = SUBSTR(CARD_DATA,7,DATALEN-7)

     
   
   SELECT 6
   SET EXCLU OFF
   USE &DR&F6
   LOCATE FOR ALLTRIM(CRDSEQNO) = ALLTRIM(FIELD_SEQNO)  
      @ 13,5 SAY 'CARD #  :'+FIELD_SEQNO

   IF FOUND()
     
      @ 14,5 SAY 'NAME    :'+ALLTRIM(CRD_FNAME)+' '+CRD_LNAME
      @ 15,5 SAY 'COMPANY :'+CRDCOMPNM
      @ 16,5 SAY 'VALIDITY:'+DTOC(CRDVALIDDT)

      DO CASE  
        CASE WHICH_CTR = 1
           FIELD_PATFIL=  ALLTRIM(HCM_PATFIL)
        CASE WHICH_CTR = 2
           FIELD_PATFIL=  ALLTRIM(HAN_PATFIL)
        CASE WHICH_CTR = 3
           FIELD_PATFIL=  ALLTRIM(VT_PATFIL)
      ENDCASE
      @ 17,5 SAY 'PAT CODE:'+FIELD_PATFIL

      DO BOX2 WITH 19,3,"IS THIS THE CARD HOLDER ? :","YES","NO",'GR+','RB','GR+','R',CARDHOLDER,.F.,.T.

      IF CARDHOLDER = 2
         LOOP
      ENDIF
 
      IF NAMEDCARD = .F. 
         @ 22,3 SAY "THIS IS AN UNNAMED CARD NO PATIENT CODE RECORDED, PLS RETRIEVE PATIEN RECORD MANUALLY"
         WAIT ' '
         TRUEPAT = .F.
      ELSE

        IF  len(alltrim(FIELD_PATFIL)) = 0  
         @ 22,3 SAY "NO PATIENT CODE RECORDED IN THE LOCAL CARD DATABASE YET, PLS RETRIEVE WITH THE NORMAL WAY"
         WAIT ' '
         TRUEPAT = .F.
        
        ELSE
                 TRUEPAT = .T.
        ENDIF
      ENDIF
      **  Update the last swipe dateso that we can turn out reports for the utilizations
      IF REC_LOCK(0)
         REPLACE CRDSWIPEDT WITH DATE()
      ENDIF
      UNLOCK

      ** update the date and time into the lcardlog.dbf
      SELE 7
      IF FIL_LOCK(0)
         APPEND BLANK
      ENDIF
      IF REC_LOCK(0)
         REPL CRDSEQNO WITH ALLTRIM(FIELD_SEQNO)
         REPL CRDSWIPEDT WITH DATE() 
         REPL CRDSWIPETM WITH TIME()

      ENDIF
      UNLOCK

      ***
   ELSE
      @ 15,5 SAY "CARD RECORD NOT FOUND -- CHECK FOR CARD'S VALIDITY !!"
      WAIT ' '
      TRUEPAT = .F.
   ENDIF
   

  
** 
ENDDO
